package EventPackage;

public class KeepAliveDispatcher extends Thread {

    private EventDispatcher event_dispatcher;
    private int keep_alive_report_time;
    private long participantId;
    private String name;
    private String description;

    private boolean running = true;

    public KeepAliveDispatcher(EventDispatcher event_dispatcher, int keep_alive_report_time, long participantId, String name, String description) {
        this.event_dispatcher = event_dispatcher;
        this.keep_alive_report_time = keep_alive_report_time;
        this.participantId = participantId;
        this.name = name;
        this.description = description;
    }

    public void run () {
        while (this.running) {
            Event evt = new Event(SensorEventManagerInterface.KEEP_ALIVE_EV_ID, this.name+"|"+this.description);
            evt.SetSenderId( participantId );
            this.event_dispatcher.add(evt);
            try { Thread.sleep(this.keep_alive_report_time); } catch (InterruptedException e) { }
        }
    }

    public void setRunning(boolean running) {
        this.running = running;
    }
}
